package com.sakura.mall.coupon.seckillSkuRelation.controller;

import com.sakura.mall.common.response.Page;
import com.sakura.mall.common.response.R;
import com.sakura.mall.coupon.seckillSkuRelation.domain.request.AddSeckillSkuRelationRequest;
import com.sakura.mall.coupon.seckillSkuRelation.domain.request.UpdateSeckillSkuRelationRequest;
import com.sakura.mall.coupon.seckillSkuRelation.domain.request.SeckillSkuRelationPageRequest;
import com.sakura.mall.coupon.seckillSkuRelation.service.SeckillSkuRelationService;
import com.sakura.mall.coupon.seckillSkuRelation.domain.vo.SeckillSkuRelationVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀活动商品关联
 *
 * @author sakura
 */
@RestController
@RequestMapping("/seckillSkuRelation")
@RequiredArgsConstructor
public class SeckillSkuRelationController {

    private final SeckillSkuRelationService seckillSkuRelationService;


    /**
     * 新建
     *
     * @return R {@link Void}
     */
    @PostMapping
    public R<Void> create(@RequestBody @Validated AddSeckillSkuRelationRequest request) {
        seckillSkuRelationService.add(request);
        return R.ok();
    }


    /**
     * 分页获取
     *
     * @return R {@link Page<SeckillSkuRelationVo>}
     */
    @GetMapping("list")
    public R<Page<SeckillSkuRelationVo>> page(SeckillSkuRelationPageRequest request) {
        Page<SeckillSkuRelationVo> ret = seckillSkuRelationService.queryPage(request);
        return R.ok(ret);
    }


    /**
     * 根据id删除
     *
     * @return R {@link Void}
     */
    @DeleteMapping("{id}")
    public R<Void> remove(@PathVariable Long id) {
        seckillSkuRelationService.removeById(id);
        return R.ok();
    }


    /**
     * 根据id更新
     *
     * @return R {@link Void}
     */
    @PostMapping("{id}")
    public R<Void> update(@PathVariable Long id, @RequestBody UpdateSeckillSkuRelationRequest request) {
        seckillSkuRelationService.updateById(id, request);
        return R.ok();
    }

}
